# -*- coding: utf-8 -*-
# @Time    : 2025/4/15 21:43
# @Author  : wangwei
# @File    : demo1.py
import jsonpath
import requests
import pytest

# class DemoTest:
#     def __init__(self):
#         self.url = "http://apis.juhe.cn/xzpd/query"
#         self.params = {
#             "men": "狮子",
#             "women": "白羊",
#             "key": "c6aa6f082901c4b7fb6e3cc2eac98b72"
#         }
#         self.session = requests.Session()
#
#     def send(self):
#         # 发送请求并获取响应
#         response = self.session.get(self.url, params=self.params)
#         print(f"接口响应状态码:{response.status_code}")
#         print(f"接口响应body信息:{response.text}")
#         return response
#
#
# # 测试代码
# def test_demo():
#     # 发送请求并解析 JSON 响应
#     res_json = DemoTest().send().json()
#     print(res_json)
#
#     # 提取 women 字段
#     women_result = jsonpath.jsonpath(res_json, "$..women")
#     if women_result:  # 检查是否找到匹配项
#         women = women_result[0]  # 取第一个匹配项
#     else:
#         women = None  # 如果未找到，设置为 None
#         print("Failed to extract 'women' from response")
#     print(women)
#
#     # 使用 pytest.assume 进行断言
#     pytest.assume(res_json.get("result", {}).get("men") == "狮子", "测试失败: men 不等于 狮子")
#     pytest.assume(women == "白羊", "测试失败: women 不等于 白羊")

json_data={"name":"wangxiao","age":"21","sex":"men"}
print(jsonpath.jsonpath(json_data, "$..name"))


# res_json = DemoTest().send().json()
# print(res_json)
#
# # 提取 women 字段
# women_result = jsonpath.jsonpath(res_json, "$..women")
# if women_result:  # 检查是否找到匹配项
#     women = women_result[0]  # 取第一个匹配项
# else:
#     women = None  # 如果未找到，设置为 None
#     print("Failed to extract 'women' from response")
# print(women)
#
# # 使用 pytest.assume 进行断言
# pytest.assume(res_json.get("result").get("men") == "狮子", "测试失败: men 不等于 狮子")
# pytest.assume(women == "白羊", "测试失败: women 不等于 白羊")

